-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java8-11 changes consistent with 17 #576
Conversation
This must wait until DS-Memory 3.0.0 is released. |
src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java
Dismissed
Show dismissed
Hide dismissed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find that the variable name changes in HeapifyWrapSerVer1and2Test.java
actually made things any clearer. Expanding the comments above each block would have been sufficient.
The use of wmem.close()
seemed arbitrary at times? Maybe it was always tied to a try-with-resources block and I didn't see that in some cases?
But we have a few tests that don't actually seem to test anything, so we should fix those. Even if the previous version was similarly flawed.
|
||
final Union union2 = SetOperation.builder().buildUnion(); //on-heap union | ||
assertFalse(union2.isSameResource(wmem2)); //obviously not | ||
wmem.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we not need to close wmem2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it has already been closed. In fact, if you try to close wmem2, it will throw an error.
The purpose of this test is to check the move and resize behavior when a sketch is off-heap.
- Note on line 193 we get sufficient bytes to hold the sketch, but on line 195 we under allocate space by half. This will force the sketch to request more memory.
- The default MemoryRequestServer will allocate new memory on the heap, and the sketch itself will move the data from wmem2 to the new heap allocation, and then resize the internal hash table into the new memory. Then the sketch will request the MRS to close wmem2, which it does.
I will add some more comments to make this test a little clearer
|
||
//The actual Memory has been re-allocated several times, | ||
// so the the wmem reference is invalid. Use the sketch to get the last memory reference. | ||
WritableMemory lastMem = usk1.getMemory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we get lastMem
but not assert anything about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The real objective of this test is to be an example for the user on how the MemoryRequestServer can be used to help with limited memory scenarios where the sketch needs to expand beyond what was allocated. This is why there are extensive code comments in this test method.
The actual test that the expansion of memory occurred (several times) and the test that the sketch continued successfully is on line 67. After that, the actual capacity of the last memory allocated is printed out just for the user. There is no reason to test it, we know that it was big enough.
No change is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in order to call it a test and pretend it means anything we should assert that the size is larger than the initial size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test of success is on line 67. By definition, if line 67 passes, the memory had to grow larger than the initial size. If the memory capacity did not grow larger than the initial size, the sketch would run out of memory and the test would fail. In fact it would fail before it ever reached line 67. So putting an extra test that the memory in fact grew beyond the initial size is redundant and impotent because that extra test would either never be executed or it would always pass.
} | ||
println(sketch.toString()); | ||
} | ||
|
||
@Test | ||
public void directSketchShouldMoveOntoHeapEventually2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't actually test anything. There's no possible failure.
Rather than break
it should set some sort of success flag and at the end of the test the success flag should be true. If it is not, the sketch did not actually move on heap. But right now we don't actually check that (and didn't before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. If wmem is still alive at the end then the test failed. I just added one line.
} | ||
} catch (final Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void checkEmptyDirect() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's again no actual test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. In the process of applying a test, I discovered a minor bug in DoublesByteArrayImp::convertToByteArray(...). This test was generating an empty sketch, which should result in a returned byte[] of only 8 bytes. And it was 8 bytes, but the preLongs value in byte 0 was 2 instead of 1. This is now fixed.
@@ -97,8 +88,7 @@ public void checkConstructorKtooSmall() { | |||
@Test//(expectedExceptions = SketchesArgumentException.class) | |||
public void checkConstructorMemTooSmall() { | |||
int k = 16; | |||
try (WritableHandle h = makeNativeMemory(k/2)) { | |||
WritableMemory mem = h.getWritable(); | |||
try (WritableMemory mem = makeNativeMemory(k/2)) { | |||
UpdateSketch.builder().setNominalEntries(k).build(mem); | |||
} catch (final Exception e) { | |||
if (e instanceof SketchesArgumentException) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the expected exceptions annotation here? It's fine if there's a reason, but that should be documented and the comment in the test annotation removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. This comment applies to two adjacent test methods as well. Fixed.
Thank you for your comments! |
This PR is targeting a DS-Java 6.1.0 release. The changes in this PR make the Java repo consistent with the just released Memory 3.0.0. This ds-java release is still targeted for Java 8 and 11 and will likely be the last release supporting Java 8 and 11. If all goes as planned, the next release will be DS-Java 7.0.0, which will be targeted at Java 17.
All of the following changes are internal and do not impact the DS-Java API.
DS-Java changes from Master to branch java8-11_changes_consistent_with_17:
common/Util.java
theta/Sketch
theta/Sketches
filters/bloomfilter
hll/DirectAuxHashMapTest
hll/DirectCouponListTest
kll/KllDoublesValidationTest
quantiles/DebugUnionTest
quantiles/DirectQuantilesMemoryRequestTest
quantiles/DoublesSketchTest
quantiles/PreambleUtilTest
theta/CompactSketchTest
theta/DirectQuickSelectSketchTest
theta/HeapifyWrapSerVer1and2Test
theta/SketchesTest
theta/UnionImplTest
theta/UpdateSketchTest
pom.xml
Readme